﻿<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:espace="espace:StringHelper">
	<xsl:output method="text" />
	<xsl:template match="/">using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Linq;
using NHibernate.Criterion;
using NHSessionFactory;
using <xsl:value-of select="Schema/@EntityNameSpace" />;
using <xsl:value-of select="Schema/@ContractsNameSpace" />;

namespace <xsl:value-of select="Schema/@NameSpace" />
{
	public class <xsl:value-of select="Schema/@TableName" />Biz :I<xsl:value-of select="Schema/@TableName" />Service
	{
		private ISessionFactory sessionFactory;

		public <xsl:value-of select="Schema/@TableName" />Biz()
		{
			sessionFactory =SessionFactory.CreateSession("TC86Common");
		}
		
		public object Save(<xsl:value-of select="Schema/@TableName" /> entity)
		{
			using (ISession session = sessionFactory.OpenSession())
			{
				var id = session.Save(entity);
				session.Flush();
				return id;
			
			}
		}
		
		public void Update(<xsl:value-of select="Schema/@TableName" /> entity)
		{
			using (ISession session = sessionFactory.OpenSession())
			{
				session.Update(entity);
				session.Flush();
				
			}
		}
		
		public void Delete(<xsl:value-of select="Schema/@TableName" /> entity)
		{
			using (ISession session = sessionFactory.OpenSession())
			{
				session.Delete(entity);
				session.Flush();
			
			}
		}
		
		public <xsl:value-of select="Schema/@TableName" /> Get(object id)
		{
			using (ISession session = sessionFactory.OpenSession())
			{
				return session.Get&lt;<xsl:value-of select="Schema/@TableName" />&gt;(id);

			}
		}
		
		public IList&lt;<xsl:value-of select="Schema/@TableName" />&gt; LoadAll()
		{
			using (ISession session = sessionFactory.OpenSession())
			{
			
				ICriteria criteria = session.CreateCriteria(typeof(<xsl:value-of select="Schema/@TableName" />));
				return criteria.List&lt;<xsl:value-of select="Schema/@TableName" />&gt;();
			
			
			}
		}

	}

}
	</xsl:template>
</xsl:stylesheet>